<script>
import IFrame from '@/components/Iframe/index.vue'
import { requestGet } from '@/api/system/common'

export default {
  name: 'ServerEntityV5',
  components: { IFrame },
  props: {
    temp: {
      type: Object,
      default: () => {
        return {}
      }
    },
    entity: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      url: '',
      stepList: []
    }
  },
  watch: {
    entity: {
      handler(newName, oldName) {
        this.url = newName.url
        this.initData(newName.id, newName.workname)
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  methods: {
    initData(workId, workName) {
      requestGet('rest/api/query/v2/workflow/step', { flag: workName, wid: workId })
        .then(res => {
          const { data } = res
          this.stepList = data.data
        })
    }
  }
}
</script>
<template>
  <div class="entity-content">
    <div class="entity-body-left">
      <div class="left-header">
        <div class="left-header-body">流程步骤</div>
      </div>
      <div class="left-content">
        <div v-for="item in stepList" :key="item.id" class="left-step-li">
          <div class="left-step-li-icon" />
          <div class="step-li-title">{{ item.name }}</div>
          <div v-if="item.history && item.history.length > 0" class="step-li-content">
            <div v-for="obj in item.history" :key="obj.startDate" class="li-user">
              <div class="li-article-line">提交与 {{ obj.finishDate }}</div>
              <div v-if="obj.summary" class="li-article">{{ obj.summary }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="entity-body-right">
      <i-frame :src="url" />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.entity-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-flow: row nowrap;

  .entity-body-left {
    width: 340px;

    .left-content {
      padding: 10px 10px 10px 20px;
      box-sizing: border-box;
    }
  }

  .entity-body-right {
    flex: 1 1;
  }
}

.left-header {
  width: 100%;
  height: 50px;
  text-align: center;
  color: #ffffff;
  line-height: 50px;
  letter-spacing: 3px;
  padding: 5px 10px;
  box-sizing: border-box;

  .left-header-body {
    font-size: 1.1rem;
    font-weight: bold;
    background-color: #409EFF;
    border-radius: 4px;
  }
}

.left-step-li {
  width: 100%;
  min-height: 80px;
  position: relative;
  border-left: 4px solid #e4e7ed;
  padding: 0 10px;
  box-sizing: border-box;

  .left-step-li-icon {
    position: absolute;
    width: 16px;
    height: 16px;
    top: 0;
    left: -10px;
    border-radius: 8px;
    background-color: #e4e7ed;
  }

  .step-li-title {
    width: 100%;
    height: 40px;
    line-height: 40px;
    text-align: left;
    font-size: 1.1rem;
    font-weight: bold;
  }

  .step-li-content {
    width: 100%;
    height: auto;
    padding: 10px;
    box-sizing: border-box;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
    border-radius: 4px;

    .li-user {
      width: 100%;
      height: auto;

      .li-article-line {
        width: 100%;
        height: 30px;
        line-height: 30px;
        font-size: 0.9rem;
        color: #303133;
      }

      .li-article {
        width: 100%;
        line-height: 20px;
        font-size: 0.8rem;
        color: #606266;
      }
    }
  }
}

.entity-body-right {
  padding: 5px;
  box-sizing: border-box;
}
</style>
